# -*- coding: utf-8 -*-
# @Time : 2021/6/25 14:56

# @Author : zhujianhao

# @File : personal-code-link.py

# @Software: PyCharm

from locust import HttpLocust, TaskSet, task
import random
from faker import Faker
from locust import HttpUser, task, between, HttpLocust
from locust import LoadTestShape
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
fake = Faker(locale='zh_CN')
import json


# def fakertime():
#     return fake.unix_time()
#
#
# def fakername():
#     return fake.company() + str('的订单') + str(random.randint(0, 999))
#
# def random_page():
#     return random.randint(1,1360)

class QuickstartUser(TaskSet):
    def on_start(self):
        pass

    @task
    def api1(self):
        headers = {
            "Host": "market-uat.tangees.com",
            "Connection": "keep-alive",
            "Content-Length": "482",
            "Accept": "*/*",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.63",
            "Content-Type": "application/json;charset=UTF-8",
            "Origin": "https://market-uat.tangees.com",
            "Sec-Fetch-Site": "same-origin",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cookie": "monitorCustomerKey=6baec0da-5588-45d0-868b-e8e49401b85e-20210630202838; webfunny_province=%E5%B9%BF%E4%B8%9C%E7%9C%81%E6%A2%85%E5%B7%9E%E5%B8%82; webfunny_ip=183.24.67.146; accountCenterSessionId=.eJwdjs1Kw0AURt9l1i7u_Gey7kZoU4pRSTZh7p07tmmJkKRqFd_dsauPA9-B8yOuC8_DKYlaOPAGEGVwYBJarnSu2PsgHgQd4zTxpZw-GQsPeeblKOp1vnKhu568zD6BgsxEmA1HMFTpFNEa0hScTNnm4HWiKkKSUtmylVfWgFYhZO8MRJmsZUAqYzD7jFKxiipqRkBH4PBfNBTJaaWQI7HUVnpJJWtiTsMSP3hY34eEos7xspTA5R7YjJ3tx7Pux8O6-3457Z4AuvENtu35tt_Qun99hqbtdLM53Pr28Uv8_gHp0FWy.E8RocA.bqA_HREIe-s5lXHL5iLCV9u01Ls",

        }
        # cookie = {
        #     "accountCenterSessionId": "eJwljs1KA0EQhN9lzjnMT8_07N6ExCA4hGBA3Msy091j1LjC7sZAxHd31UNBUfBV1ZeiYx4GOalWXaSolZpeePFpvdG7x_2lW9_M3TaZ3YPW3SFd7w_Pvtvu5_SafPd-55LduKfr7dsC9n8gYuMjW6dzAbRcpQKiY87IvmryGsjoApVMiJVro0F0DmitLAKikIEYIuQQyHhjTXTWIkcM1QkJBiriIhkwSytJFCkNBwQrxB6b-nukjjIdVTuPZ1mpQYT7KX9KP3_0XFRb82la8vMk4__loF1FDk0TNHAx5JdNsNar7x8EiVPj.E6NBrw.T9q6TjIu-q0AUTJWMrQK2cZsesI"
        # }
        payload = {"contentType": ["1"], "pageNum": 1, "pageSize": 10}
        # https://market-uat.tangees.com
        # with self.client.post(url='/web/company/moment/queryList', headers=header, data=json.dumps(payload),
        with self.client.post(url='/web/virtual/moment/getMomentList', headers=headers, data=json.dumps(payload),
                              catch_response=True) as response:
            if response.status_code == 200:
                try:
                    json.loads(response.text)['errMsg'] == 'success！'
                except:
                    response.failure("Timeout")
            else:
                response.failure(response.status_code)
                # response.failure("No data")

    # @task(1)
    # def api2(self):
    #     header = {
    #         "Host": "scrm-test.tangees.com",
    #         "Connection": "keep-alive",
    #         "Content-Length": "482",
    #         "Accept": "*/*",
    #         "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.63",
    #         "Content-Type": "application/json;charset=UTF-8",
    #         "Origin": "https://scrm-test.tangees.com",
    #         "Sec-Fetch-Site": "same-origin",
    #         "Sec-Fetch-Mode": "cors",
    #         "Sec-Fetch-Dest": "empty",
    #         "Referer": "https://scrm-test.tangees.com/customer-migration/resign-inheritance/group",
    #         "Accept-Encoding": "gzip, deflate, br",
    #         "Accept-Language": "zh-CN,zh;q=0.9",
    #         "Cookie": "accountCenterSessionId=.eJw9j01PwzAQRP-Lzz2sP3Zt9wipeiGgIiBKL5HX3qhtSpCaAFIR_50IJI5PmhnN-1Ldsai1MhRjpBJj8oG8xqxBnLGag4FIOWQbjDMxG01AiAk1Ijmy2dueOKelm0UCIYmG4jJkKhjYYDGlMAiKsdYyWxEDQWe06DxLcU6iTWDVSuVDGkc5L2c-hRceRUo3pQ_p5reusFr36TzJSnX9RabDP75PcvlzINBeknPgNacMzI4XlRKWrek30J7uX9unnWmbzVw3-1N9C9BeH4e7ZnOtq3reb5_hYbvDuroZ9tXLoL5_ANzIU4Q.E6G69g.MwjpoEh3n2s28v5wq2rL7tp9gDA",
    #     }
    #     cookie = {
    #         "accountCenterSessionId": ".eJw9j01PwzAQRP-Lzz2sP3Zt9wipeiGgIiBKL5HX3qhtSpCaAFIR_50IJI5PmhnN-1Ldsai1MhRjpBJj8oG8xqxBnLGag4FIOWQbjDMxG01AiAk1Ijmy2dueOKelm0UCIYmG4jJkKhjYYDGlMAiKsdYyWxEDQWe06DxLcU6iTWDVSuVDGkc5L2c-hRceRUo3pQ_p5reusFr36TzJSnX9RabDP75PcvlzINBeknPgNacMzI4XlRKWrek30J7uX9unnWmbzVw3-1N9C9BeH4e7ZnOtq3reb5_hYbvDuroZ9tXLoL5_ANzIU4Q.E6G69g.MwjpoEh3n2s28v5wq2rL7tp9gDA"
    #     }
    #     payload = {'pageSize':10,'pageNum':1}
    #     with self.client.post(url='/test/web/inherit/offline/externalcontact/list', headers=header, cookies=cookie,data=json.dumps(payload),
    #                           catch_response=True) as response:
    #         if response.status_code == 200:
    #             if json.loads(response.text)['errMsg'] == 'success！':
    #                 print(response.text)
    #             else:
    #                 response.failure("Timeout")
    #         else:
    #             response.failure("No data")

    # @task(1)
    # def api3(self):
    #     header = {
    #         "Host": "scrm-test.tangees.com",
    #         "Connection": "keep-alive",
    #         # "Content-Length": "482",
    #         "Accept": "*/*",
    #         "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.63",
    #         # "Content-Type": "application/json;charset=UTF-8",
    #         "Origin": "https://scrm-test.tangees.com",
    #         "Sec-Fetch-Site": "same-origin",
    #         "Sec-Fetch-Mode": "cors",
    #         "Sec-Fetch-Dest": "empty",
    #         "Referer": "https://scrm-test.tangees.com/customer-migration/resign-inheritance/group",
    #         "Accept-Encoding": "gzip, deflate, br",
    #         "Accept-Language": "zh-CN,zh;q=0.9",
    #         "Cookie": "accountCenterSessionId=.eJw9j01PwzAQRP-Lzz2sP3Zt9wipeiGgIiBKL5HX3qhtSpCaAFIR_50IJI5PmhnN-1Ldsai1MhRjpBJj8oG8xqxBnLGag4FIOWQbjDMxG01AiAk1Ijmy2dueOKelm0UCIYmG4jJkKhjYYDGlMAiKsdYyWxEDQWe06DxLcU6iTWDVSuVDGkc5L2c-hRceRUo3pQ_p5reusFr36TzJSnX9RabDP75PcvlzINBeknPgNacMzI4XlRKWrek30J7uX9unnWmbzVw3-1N9C9BeH4e7ZnOtq3reb5_hYbvDuroZ9tXLoL5_ANzIU4Q.E6Gviw.KnO5ggzOaANqttG4biN8dSbVaVg",
    #     }
    #     cookie = {
    #         "accountCenterSessionId": ".eJw9j01PwzAQRP-Lzz2sP3Zt9wipeiGgIiBKL5HX3qhtSpCaAFIR_50IJI5PmhnN-1Ldsai1MhRjpBJj8oG8xqxBnLGag4FIOWQbjDMxG01AiAk1Ijmy2dueOKelm0UCIYmG4jJkKhjYYDGlMAiKsdYyWxEDQWe06DxLcU6iTWDVSuVDGkc5L2c-hRceRUo3pQ_p5reusFr36TzJSnX9RabDP75PcvlzINBeknPgNacMzI4XlRKWrek30J7uX9unnWmbzVw3-1N9C9BeH4e7ZnOtq3reb5_hYbvDuroZ9tXLoL5_ANzIU4Q.E6Gviw.KnO5ggzOaANqttG4biN8dSbVaVg"
    #     }
    #     param = {'pageSize': 10, 'pageNum': 1}
    #     with self.client.get(url='https://scrm-test.tangees.com/test/web/inherit/offline/group/list', headers=header, verify=False, params=param,catch_response=True) as response:
    #         if response.status_code == 200:
    #             if json.loads(response.text)['errMsg'] == 'success！':
    #                 pass
    #             else:
    #                 response.failure("Timeout")
    #         else:
    #             response.failure("No data")

    def on_stop(self):
        pass


class WebsiteUser(HttpUser):
    tasks = [QuickstartUser]
    host = "https://market-uat.tangees.com"
    wait_time = between(0.1, 0.5)  # 多少秒用户发起1次请求


if __name__ == "__main__":
    import os

    os.system("locust -f locust_1.py --web-host=127.0.0.1")
